import asyncio
import json
import os
import socket

import openpyxl as openpyxl

wb = openpyxl.load_workbook('Include/Python sensitive APIs.xlsx')
sheets = wb.worksheets
sheet1 = sheets[0]
# print(sheet1[1])
base_index = 65
col_index = 0
sources_dict = {}
sinks_dict = {}
sourcesinks_dict = {}
dangers_dict = {}
dict_list = [sources_dict, sinks_dict, sourcesinks_dict, dangers_dict]
while col_index < 4:
    api_col = sheet1[chr(base_index + col_index * 2)]
    type_col = sheet1[chr(base_index + col_index * 2 + 1)]
    for i in range(1, len(api_col)):
        if api_col[i].value:
            type = type_col[i].value
            if '=HYPERLINK' in api_col[i].value:
                api = api_col[i].value.split('","')[1][:-2]
            else:
                api = api_col[i].value
            api = api.split('(')[0]
            if type in dict_list[col_index]:
                dict_list[col_index][type].append(api)
            else:
                dict_list[col_index][type] = [api]
    col_index = col_index + 1
for i in range(len(dict_list)):
    print(dict_list)

api_json = json.dumps(dict_list, indent=4)
api_file = open('api.json', 'w', encoding='utf-8')
api_file.write(api_json)
